#include "Timestamp.h"
#include <time.h>

Timestamp::Timestamp() : microSecondsSinceEpoch_(0){};

Timestamp::Timestamp(int64_t microSecondsSinceEpoch)
    : microSecondsSinceEpoch_(microSecondsSinceEpoch){};

Timestamp Timestamp::now() {
  time_t now = time(nullptr);
  return Timestamp(now);
};

std::string Timestamp::toString() const {
  char buf[128] = {0};
  tm *localTime = localtime(&microSecondsSinceEpoch_);
  snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d",
           localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
           localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
    return std::string(buf);
};


// int main() {
//   Timestamp ts = Timestamp::now();
//   std::cout << "Current timestamp: " << ts.toString() << std::endl;
//   return 0;
// }   